////////////////////////////////////////////////////////////////////////////////
//
//	This file is part of Woozox, see <http://code.google.com/p/woozox/>.
//
//	Copyright 2008-2009 Florian David
//
//	Woozoo is free software: you can redistribute it and/or modify
//	it under the terms of the GNU Lesser General Public License as 
//	published by the Free Software Foundation, either version 3 of 
//	the License, or (at your option) any later version.
//
//	Woozoo is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//	GNU General Public License for more details.
//
//	You should have received a copy of the GNU Lesser General Public 
//	License along with Woozoo. If not, see <http://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////////////
package org.woozoo.xhtml.core.base.selector
{
	import org.woozoo.xhtml.core.base.*;

	/**
	 * @private
	 * */
	internal final class SelectorOperatorPound extends AbstractSelectorOperator
	{
		override protected function _prepareString(str:String) : String {
			return str.replace('#', '');
		}
		
		override protected function _operateChildrenElements(checkElements : Boolean) : Array {
			var res : Array = [];
			for (var i : int = 0; i < elementsLength; i++) {
				var element : Element = getElementAt(i);
				if (checkElements && element.id == str) {
					res.push(element);
				}
				res = res.concat(element.getElementsByAttributeEqualTo('id', str));
			}
			return res;
		}
		
		override protected function _operateElements() : Array {
			debugFunction('we interpret # with already result '+str+ ' : we look on all element');
			var res : Array = [];
			var element : Element;
			for (var i : int = 0; i < elementsLength; i++) {
				element = getElementAt(i);
				if (element.id == str) {
					res.push(element);
				}
			}
			return res;
		}
	}
}